package com.hdlang.android.v2.patch.plugin;

import com.android.build.api.instrumentation.FramesComputationMode;
import com.android.build.api.instrumentation.InstrumentationScope;
import com.android.build.api.variant.AndroidComponentsExtension;
import com.android.build.api.variant.Variant;

import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.logging.Logger;

public class RobustPlugin implements Plugin<Project> {
    public static Logger logger = null;

    @Override
    public void apply(Project project) {
        logger = project.getLogger();
        final AndroidComponentsExtension extension = project.getExtensions().getByType(AndroidComponentsExtension.class);
        extension.onVariants(extension.selector().all(), (Action<Variant>) variant -> {
            variant.getInstrumentation().transformClassesWith(RobustTransform.class, InstrumentationScope.PROJECT, none -> null);
            variant.getInstrumentation().setAsmFramesComputationMode(FramesComputationMode.COMPUTE_FRAMES_FOR_INSTRUMENTED_METHODS);
        });
    }
}
